<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019-02-25
  Time: 14:54
--%>
<html>
<head>
    <script type="text/javascript" src=".././static/js/public-head.js"></script>
</head>
<body>

<form class="layui-form" action="javascript:;" lay-filter="rpt-form"  >
    <input type="hidden" lay-submit lay-filter="down2007">
    <div id="page-header">

    </div>
    <hr>
</form>
<div class="layui-fluid" id="page-body" >
</div>
</body>

<script type="text/javascript" src="js/report.js"></script>
<script type="text/javascript">
    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'table','form','formSelects' ,'element','laydate',"upload"  ], function() {
        var $ = layui.$;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var layer = layui.layer;
        var table = layui.table;
        var element = layui.element;
        var laydate = layui.laydate;
        var layindex;
        var upload = layui.upload;

        //获取rpt基本配置
        $.getJSON(basePath+"/xdWidgetReport/getOne"+urlParam, function (rstHtml) {
            if(rstHtml.code!=0){
                layer.msg(rstHtml.msg)
            }else{
                $("#page-header").append(rstHtml.data.viewHeader)
                $("#page-body").append(rstHtml.data.viewBody)
                $("#page-header .layui-form-item").append('<div class="layui-inline"><button class=layui-btn lay-submit  id=rpt-query  lay-filter=rpt-query>查询</button></div>')
                //解析查询条件
                $.getJSON(basePath+"/xdWidgetReport/getRptBusinessCfg"+urlParam,function(rst){

                    if(rst.code !=0){
                        layer.alert("异常:<br>"+rst.msg,{icon:2})
                        return
                    }

                    var allSelect = {} //所有的select
                    var eventMap = {}
                    $.each(rst.formItem,function(index,item){
                        if(item.classFlag == "xd-date"){
                            laydate.render({elem:"#"+item.name,type:item.type,value: new Date(commonUtil.setDefaultDate(item.defaultValue)),theme:item.theme})
                        }else if(item.classFlag =="xd-select" ){
                            allSelect[item.name] = item
                            if(item.events!=null && item.events !== ""){
                                eventMap[item.name] = item
                            }
                        }
                    })
                    //初始化级select,以及级联事件
                    reportModelUtil.initSelect(formSelects,allSelect,eventMap)
                    reportModelUtil.initTable(form,table,rst.table,upload)
                })

                form.render('radio');
            }
        })

    })


    /*

     var viewPanelTableUtil = {
     panelId:"",
     renderArray:[],
     downLoadTmp:function(panelId){//下载模板文件
     var indexLoad =  layer.load()
     var url = basePath+"/xdWidgetPanel/createExcelTmp?panelId="+panelId ;
     $.getJSON(url,function(rst){
     layer.close(indexLoad)
     //console.log(rst)
     if(rst.code == 0){
     window.open(basePath+"/specialDownLoad/doXLSXByTempFileAndFileName?fileName="+rst.data.fileName +"&tempFile="+rst.data.tempFile)
     }else{
     layer.alert("下载异常：<br>"+rst.msg,{icon:2})
     }
     })
     },
     upLoadXLSX:function(panelId,upload,layid){
     var upDom =   $("div[lay-id="+layid+"] .layui-table-tool-temp").find("button[lay-event=upLoad]")
     upload.render({elem:upDom,
     url:basePath+"/specialUpLoad/doUpdLoadXdPanelDataByXLSX",
     data:{panelId:panelId},
     accept:"file",
     exts:"xlsx",
     acceptMime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
     before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
     layer.load()
     },
     done:function(res){
     layer.closeAll()
     //console.log(res)
     if(res.code !=0){
     layer.alert(res.msg)
     }else{
     layer.msg("文件上传成功，正在写入表...",{icon:6},function(){
     layer.load()
     $.getJSON(basePath+"/specialUpLoad/importXlsx2TableByPanelId",{tempFile:res.data,panelId:panelId},function(rst){
     layer.alert(rst.msg,{icon: 6},function(){
     layer.closeAll()
     })
     })
     })
     }
     },
     error:function(){
     layer.alert("上传文件异常，请重试",function(){
     layer.closeAll()
     })
     }
     })
     },

     initTable:function(form,table,tableArray,upload){//初始化table

     $.each(tableArray,function(index,tableOption){
     //console.log(tableOption)
     tableOption.done = function(res, curr,count){
     if(tableOption.page == false){
     commonUtil.mergeCell(tableOption.id,tableOption.mergeField)
     }
     viewPanelTableUtil.upLoadXLSX(tableOption.widgetPanelId,upload,tableOption.id)

     }

     if(tableOption.queryFlag){
     table.render(tableOption)
     }

     if(tableOption.autoFlag){
     setInterval(function(){
     table.render(tableOption)
     },(1000*60) * tableOption.autoInterval );
     }

     table.on("toolbar("+tableOption.id+")",function(obj){
     var event = obj.event;
     switch (event){
     case "downLoad":
     form.on("submit(down2007)",function(objs){
     var indexLoad =  layer.load()
     var url = basePath+"/xdWidgetPanel/createExcel2007?panelId="+ tableOption.widgetPanelId;
     $.post(url,objs.field,function(rst){
     layer.close(indexLoad)
     //console.log(rst)
     if(rst.code == 0){
     window.open(basePath+"/specialDownLoad/doXLSXByTempFileAndFileName?fileName="+tableOption.title +"&tempFile="+rst.data.tempFile)
     }else{
     layer.alert("下载异常：<br>"+rst.msg,{icon:2})
     }
     },"json")
     })
     $("[lay-filter=down2007]").click()
     break;
     case "downLoadTmp":
     //console.log(event,panelId)
     viewPanelTableUtil.downLoadTmp(tableOption.widgetPanelId)
     break;
     case "upLoad":
     break;
     }
     })

     })


     form.on("submit(rpt-query)", function (obj) {
     $.each(tableArray,function(index,tableOption){
     tableOption.where = obj.field
     table.render(tableOption)
     })
     })

     },
     initSelect:function(formSelects,allSelect,eventMap){
     var existsSelect = []
     $.each(allSelect,function(key,item){//先初始化
     if(item.serverFlag){
     formSelects.data(item.name, 'server', {//远程根据 keyword 查询
     type:"post",
     data:{id:item.id},
     searchUrl:basePath+"/xdWidgetSelect/selectView"
     });
     }else{
     formSelects.render(item.name)
     }
     })
     $.each(eventMap,function(eventSelect,item){//添加级联事件
     formSelects.on(eventSelect, function(id, vals, val, isAdd, isDisabled){
     var valueAarray = {}
     $.each(item.events.split(";"),function(index,targetSelect){
     var eventValue = formSelects.value(eventSelect , 'valStr' )
     valueAarray[eventSelect] = eventValue
     if(allSelect[targetSelect] != null){
     if(allSelect[targetSelect].serverFlag){
     valueAarray.id = allSelect[targetSelect].id
     formSelects.config(targetSelect, {
     data:valueAarray
     }).data(targetSelect, 'server', {
     url:basePath+"/xdWidgetSelect/selectView"
     });
     }else{
     formSelects.search(targetSelect, eventValue);
     }
     }
     })
     },true);
     })
     }
     }

     */

</script>
</html>